<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
<!--    <meta http-equiv="Content-Type" content="multipart/form-data; charset=utf-8" />-->


    <title>资源浏览</title>
    <meta name="keywords" content="H+后台主题,后台bootstrap框架,会员中心主题,后台HTML,响应式后台">
    <meta name="description" content="H+是一个完全响应式，基于Bootstrap3最新版本开发的扁平化主题，她采用了主流的左右两栏式布局，使用了Html5+CSS3等现代技术">

    <link rel="shortcut icon" href="../../static/favicon.ico">
    <link href="../../static/css/bootstrap.min.css?v=3.3.6"
          th:href="@{/static/css/bootstrap.min.css (v='3.3.6')}"
          rel="stylesheet">
    <link href="../../static/css/font-awesome.css?v=4.4.0"
          th:href="@{/static/css/font-awesome.css  (v='4.4.0')}"
          rel="stylesheet">
    <link href="../../static/css/plugins/bootstrap-table/bootstrap-table.min.css"
          th:href="@{/static/css/plugins/bootstrap-table/bootstrap-table.min.css}"
          rel="stylesheet">
    <link href="../../static/css/animate.css"
          th:href="@{/static/css/animate.css}"
          rel="stylesheet">
    <link href="../../static/css/style.css?v=4.1.0"
          th:href="@{/static/css/style.css (v='4.1.0')}"
          rel="stylesheet">
    <!-- Sweet Alert -->
    <link href="../../static/css/plugins/sweetalert/sweetalert.css"
          th:href="@{/static/css/plugins/sweetalert/sweetalert.css}"
          rel="stylesheet">
    <!--switchery-->
    <link href="../../static/css/plugins/switchery/switchery.css"
          th:href="@{/static/css/plugins/switchery/switchery.css}"
          rel="stylesheet">
    <style type="text/css">
        .table > thead > tr > th {
            color: #2a62bc;
        }
    </style>
</head>
<body class="gray-bg">
<div class="wrapper wrapper-content animated fadeInRight">
    <div class="row text-left" style="margin-bottom: 15px; padding-left: -4px">
        <div class="col-md-9">
            <form class="form-inline" id="resource_search">
                <div class="form-group">
                    <label class="label_text">文件类型:</label>
                    <div class="input-group input-s-sm" style="width: 130px">
                        <input type="text" hidden id="#resource_suffix">
                        <input type="text" class="form-control" name="resourceSuffix" id="resourceSuffix">
                        <div class="input-group-btn">
                            <button type="button" class="btn btn-white dropdown-toggle" data-toggle="dropdown">
                                <span class="caret"></span>
                            </button>
                            <ul class="dropdown-menu dropdown-menu-right" role="menu">
                            </ul>
                        </div>
                    </div>
                </div>
                <!--|||||||||||||||||||||||||-->
                <div class="form-group">
                    <label for="resourceName" class="label_text">名称:</label>
                    <div class="input-group input-s-sm" style="width: 120px">
                        <input type="text" class="form-control input-sm" id="resourceName" name="resourceName">
                        <div class="input-group-btn">
                            <ul class="dropdown-menu dropdown-menu-right" role="menu">
                            </ul>
                        </div>
                    </div>
                </div>
                <div class="form-group" id="date_case_1">
                    <label class="label_text">时间:</label>
                    <div class="input-daterange input-group" id="datepicker">
                        <input type="text" class="input-sm form-control" style="width: 100px;" name="interviewTimeStart"
                        />
                        <span class="input-group-addon">到</span>
                        <input type="text" class="input-sm form-control" style="width: 100px;" name="interviewTimeEnd"
                        />
                    </div>
                </div>
                <button type="button" class="btn btn-primary btn-sm" id="queryBtn">查询</button>
            </form>
        </div>
        <div class="col-md-3 text-right" style="padding-left: 10px">
            <button class="btn btn-success" data-toggle="modal" data-target="#add_resource">添加</button>
            <button class="btn btn-danger" id="deleteAll">删除</button>
        </div>
    </div>

    <!-- 动态数据处理 -->
    <div>
        <table id="tb_major"></table>
    </div>
</div>
<!--更新资源模态框-->
<div class="modal fade" id="update_resource" tabindex="-1">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <span class="close" data-dismiss="modal">&times;</span>
                <h3 class="modal-title">修改</h3>
            </div>
            <div class="modal-body" style="min-height: 400px;margin-top: 20px">
                <form th:action="@{/resources/resourceList/updateResource}" class="form-horizontal" method="post"
                      id="update_form"
                      enctype="multipart/form-data">
                    <div class="form-group">
                        <label class="col-sm-3 control-label right">
                            <input type="text" id="update_id" name="id" hidden>
                            资源名称：</label>
                        <div class="col-sm-7">
                            <input type="text" class="form-control" name="resourceName" placeholder="请输入标题"
                                   id="upd_resourceName">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-3 control-label right">选择文件：</label>
                        <div class="col-sm-7">
                            <input type="file" class="form-control" name="file" id="upd_file">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-3 control-label right">资源类型：</label>
                        <div class="col-sm-7">
                            <div class="input-group">

                                <input type="text" class="form-control org1" name="type" id="upd_type">
                                <div class="input-group-btn" style="z-index:99999!important;">
                                    <button type="button" class="btn btn-white dropdown-toggle" data-toggle="dropdown">
                                        <span class="caret"></span>
                                    </button>
                                    <ul class="dropdown-menu dropdown-menu-right" role="menu">
                                    </ul>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="form-group  c_hidden">
                        <label class="col-sm-3 control-label right">课程：</label>
                        <div class="col-sm-7">
                            <div class="input-group">
                                <input type="text" hidden id="updCourseId">
                                <input type="text" class="form-control org2" name="course" id="upd_course">
                                <div class="input-group-btn" style="z-index:99999!important;">
                                    <button type="button" class="btn btn-white dropdown-toggle" data-toggle="dropdown">
                                        <span class="caret"></span>
                                    </button>
                                    <ul class="dropdown-menu dropdown-menu-right" role="menu">
                                    </ul>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="form-group  c_hidden">
                        <label class="col-sm-3 control-label right">章：</label>
                        <div class="col-sm-7">
                            <div class="input-group">
                                <input type="text" hidden id="updChapterId">
                                <input type="text" class="form-control org3" name="chapter" id="upd_chapter">
                                <div class="input-group-btn" style="z-index:99999!important;">
                                    <button type="button" class="btn btn-white dropdown-toggle" data-toggle="dropdown">
                                        <span class="caret"></span>
                                    </button>
                                    <ul class="dropdown-menu dropdown-menu-right" role="menu">
                                    </ul>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="form-group  c_hidden">
                        <label class="col-sm-3 control-label right">节：</label>
                        <div class="col-sm-7">
                            <div class="input-group">
                                <input type="text" hidden id="updSectionId">
                                <input type="text" class="form-control org4" name="section" id="upd_section">
                                <div class="input-group-btn" style="z-index:99999!important;">
                                    <button type="button" class="btn btn-white dropdown-toggle" data-toggle="dropdown">
                                        <span class="caret"></span>
                                    </button>
                                    <ul class="dropdown-menu dropdown-menu-right" role="menu">
                                    </ul>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-3 control-label right">资源描述：</label>
                        <div class="col-sm-7">
                            <textarea class="form-control" type="text" name="resourceDesc"
                                      id="upd_resourceDesc"></textarea>
                        </div>
                    </div>

                </form>
            </div>
            <div class="modal-footer">
                <button class="btn btn-white" data-dismiss="modal">关闭</button>
                <button class="btn btn-primary" id="update_sure">确定</button>
            </div>
        </div>
    </div>
</div>

<!--添加资源模态框-->
<div class="modal fade" id="add_resource" tabindex="-1">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <span class="close" data-dismiss="modal">&times;</span>
                <h3 class="modal-title">新增</h3>
            </div>

            <div class="modal-body" style="min-height: 400px;margin-top: 20px">
                <form th:action="@{/resources/resourceList/addResource}" class="form-horizontal" method="post"
                      enctype="multipart/form-data" name="add_form" id="add_form">
                    <div class="form-group">
                        <label class="col-sm-3 control-label right">资源名称：</label>
                        <div class="col-sm-7">
                            <input type="text" class="form-control" name="resourceName" placeholder="请输入标题"
                                   id="add_resourceName">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-3 control-label right">选择文件：</label>
                        <div class="col-sm-7">
                            <input type="file" class="form-control" name="file" id="add_file">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-3 control-label right">资源类型：</label>
                        <div class="col-sm-7">
                            <div class="input-group">
                                <input type="text" class="form-control org1" name="type" id="add_type">
                                <div class="input-group-btn" style="z-index:99999!important;">
                                    <button type="button" class="btn btn-white dropdown-toggle" data-toggle="dropdown">
                                        <span class="caret"></span>
                                    </button>
                                    <ul class="dropdown-menu dropdown-menu-right" role="menu">
                                    </ul>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="form-group c_hidden">
                        <label class="col-sm-3 control-label right">课程：</label>
                        <div class="col-sm-7">
                            <div class="input-group">
                                <input type="text" hidden id="courseId">
                                <input type="text" class="form-control org2" name="course" id="add_course">
                                <div class="input-group-btn" style="z-index:99999!important;">
                                    <button type="button" class="btn btn-white dropdown-toggle" data-toggle="dropdown">
                                        <span class="caret"></span>
                                    </button>
                                    <ul class="dropdown-menu dropdown-menu-right" role="menu">
                                    </ul>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="form-group c_hidden">

                        <label class="col-sm-3 control-label right">章：</label>
                        <div class="col-sm-7">
                            <div class="input-group">
                                <input type="text" hidden id="chapterId">
                                <input type="text" class="form-control org3" name="chapter" id="add_chapter">
                                <div class="input-group-btn" style="z-index:99999!important;">
                                    <button type="button" class="btn btn-white dropdown-toggle" data-toggle="dropdown">
                                        <span class="caret"></span>
                                    </button>
                                    <ul class="dropdown-menu dropdown-menu-right" role="menu">
                                    </ul>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="form-group c_hidden">

                        <label class="col-sm-3 control-label right">节：</label>
                        <div class="col-sm-7">
                            <div class="input-group">
                                <input type="text" hidden id="sectionId">
                                <input type="text" class="form-control org4" name="section" id="add_section">
                                <div class="input-group-btn" style="z-index:99999!important;">
                                    <button type="button" class="btn btn-white dropdown-toggle" data-toggle="dropdown">
                                        <span class="caret"></span>
                                    </button>
                                    <ul class="dropdown-menu dropdown-menu-right" role="menu">
                                    </ul>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-3 control-label right">资源描述：</label>
                        <div class="col-sm-7">
                            <textarea class="form-control" type="text" name="add_resourceDesc"
                                      id="add_resourceDesc"></textarea>
                        </div>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-white" data-dismiss="modal">关闭</button>
                <button type="button" class="btn btn-primary" id="add_sure">确定</button>
            </div>
        </div>
    </div>
</div>
<!-- 全局js -->
<script src="../../static/js/jquery.min.js?v=2.1.4"
        th:src="@{/static/js/jquery.min.js}"></script>
<script src="../../static/js/bootstrap.min.js?v=3.3.6"
        th:src="@{/static/js/bootstrap.min.js}"></script>

<!-- 自定义js -->
<script src="../../static/js/content.js?v=1.0.0"
        th:src="@{/static/js/content.js}"></script>

<!-- 自定义js -->
<!-- 主要用于表格的删除按钮功能实现 -->
<script src="../../static/public/exam/tableOperation.js"
        th:src="@{/static/public/exam/tableOperation.js}"></script>

<!-- Bootstrap table -->
<script src="../../static/js/plugins/bootstrap-table/bootstrap-table.min.js"
        th:src="@{/static/js/plugins/bootstrap-table/bootstrap-table.min.js}"></script>
<script src="../../static/js/plugins/bootstrap-table/bootstrap-table-mobile.min.js"
        th:src="@{/static/js/plugins/bootstrap-table/bootstrap-table-mobile.min.js}"></script>
<script src="../../static/js/plugins/bootstrap-table/locale/bootstrap-table-zh-CN.min.js"
        th:src="@{/static/js/plugins/bootstrap-table/locale/bootstrap-table-zh-CN.min.js}"></script>
<!--动态搜索-->
<script src="../../static/js/plugins/suggest/bootstrap-suggest.min.js"
        th:src="@{/static/js/plugins/suggest/bootstrap-suggest.min.js}"></script>
<!-- Sweet alert -->
<script src="../../static/js/plugins/sweetalert/sweetalert.min.js"
        th:src="@{/static/js/plugins/sweetalert/sweetalert.min.js}"></script>
<!-- Switchery -->
<script src="../../static/js/plugins/switchery/switchery.js"
        th:src="@{/static/js/plugins/switchery/switchery.js}"></script>
<!--时间控件 -->
<script src="../../static/js/plugins/datapicker/bootstrap-datepicker.js"
        th:src="@{/static/js/plugins/datapicker/bootstrap-datepicker.js}"></script>
<script src="../../static/js/plugins/datapicker/bootstrap-datepicker.zh-CN.min.js"
        th:src="@{/static/js/plugins/datapicker/bootstrap-datepicker.zh-CN.min.js}"></script>
<script>
    $(function () {
        //初始化表格
        var init = new initdata();
        init.Init();
        //点击按钮开始搜索
        $("#queryBtn").click(function () {

            var dataList = new Array('resourceSuffix','resourceName');
            querySearch('form[id="resource_search"]',dataList);

        });

        /*查询记录操作*/
        function querySearch(eventParentName, dataList, success) {
            var queryList = dataList;
            var queryMap = new Map();
            var queryNullList = new Array()
            queryList.forEach(function (item, index) {
                var event = $('' + eventParentName + ' input[name=' + item + ']');
                event.val() == "" ?
                    queryNullList.push($('' + eventParentName + ' input[name=' + item + ']'))
                    : queryMap.set(event.attr('name'), event.val());
            })

            var formData="";
            queryMap.forEach(function (value, key){
                formData += key +'='+value +'&';
            });
            formData = formData.substr(0,formData.length - 1);
            //发送ajax 查询
            $.ajax({
                url: "/owep/resources/resourceList/search",
                method: "post",
                async: true,
                data:$("#resource_search").serialize(),
                dataType: "json",   //期望服务端返回的数据类型
                //contentType: "application/json",
                success: function (data) {
                    console.log(data.toString());
                    //重新加载页面
                    console.log($('#tb_major'));

                    $('#tb_major').bootstrapTable("load", data);
                },
                error: function (jqXHR) {
                    swal("搜索失败！", "未知错误", "error");
                }
            });
            if (queryNullList.length > 0) {
                swal("搜索失败", "搜索数据不允许为空", "error");
                /*       queryNullList.forEach(function (item) {
                           item.css('border-color',"#f8ac59");
                       })*/
            } else {
                swal("搜索成功！", "已为你重新加载数据", "success")
            }

            queryMap.forEach(function (key,value) {
                console.log(value);
                $(''+eventParentName+' input[name='+value+']').css('border-color',"");
            })
        }


        //删除所有
        $('#deleteAll').click(function () {
            // 删除按钮事件
            if (!confirm("是否确认删除？"))
                return;
            var rows = $("#tb_major").bootstrapTable('getSelections');// 获得要删除的数据
            if (rows.length == 0) {// rows 主要是为了判断是否选中，下面的else内容才是主要
                alert("请先选择要删除的记录!");
                return;
            } else {
                var ids = new Array();// 声明一个数组 该数组将要存放所有选择的id
                $(rows).each(function () {// 通过获得别选中的来进行遍历
                    ids.push(this.id);// cid为获得到的整条数据中的一列
                });
                var idlist = JSON.stringify(ids);

                $.ajax({
                    url: "/owep/resources/resourceList/deleteSelectResource",
                    method: "post",
                    data: idlist,
                    dataType: "text",
                    async: "true",
                    contentType: "application/json",
                    success: function (data) {
                        console.log(data.toString());
                        /*重新加载本页面*/
                        window.location.reload();
                    },
                    error: function (jqXRH) {
                        console.log("jqXRH = " + jqXRH);
                        alert("删除失败")
                    }
                })

            }
        });


        /*添加提交表单*/
        /*$('#add_sure').click(function () {

            let myform = document.forms["add_form"];
            let formData = new FormData(myform);
            console.log(myform);
            console.log(formData);

            //资源名称
            let resourceName = $("#add_resourceName").val();

            //文件分类【课程资源：0，公共资源: 1】
            let type = $("#add_type").val();

            //资源描述
            let resourceDesc = $("#add_resourceDesc").val();

            //获取上传文件信息
            let file = $("#add_file")[0].files[0];
            //获取资源扩展名
            let resourceSuffix = file.name.substr(file.name.lastIndexOf(".")).toLowerCase();

            console.log("resourceSuffix = " + resourceSuffix);

            //获取文件大小
            let resourceSize = file.size;

            console.log("resourceSize = " + resourceSize);

            //最后一次修改时间【在此做上传时间】
            let createTime = file.lastModifiedDate;

            console.log("createTime = " + createTime);

            let course = $("#add_course").val();

            let chapter = $("#add_chapter").val();

            let section = $("#add_section").val();

            let resourceData = {};

            if (type = 1) {
                resourceData = {
                    resourceName: resourceName,
                    resourceDesc: resourceDesc,
                    resourceSuffix: resourceSuffix,
                    resourceSize: resourceSize,
                    type: type,
                    createTime: createTime
                };
            } else if (type = 0) {
                resourceData = {
                    resourceName: resourceName,
                    resourceDesc: resourceDesc,
                    resourceSuffix: resourceSuffix,
                    resourceSize: resourceSize,
                    type: type,
                    createTime: createTime,
                    course: course,
                    chapter: chapter,
                    section: section
                };
            }

            console.log(resourceData);

            /!* let resourceJson = JSON.stringify(resourceData);*!/

            $.ajax({
                method: "post",
                url: "/owep/resources/resourceList/addResource",
                async: "true",
                processData: false,
                contentType: false,
                data: formData,
                dataType: "text",
                /!*contentType:"application/json",*!/
                success: function (data) {
                    console.log(data);
                    window.location.reload();
                },
                error: function (jqXRH) {
                    console.log(jqXRH);
                    alert("添加未成功")
                }
            });
        });*/

        /*修改提交表单*/
        $('#update_sure').click(function () {
            let id = $("#update_id").val();
            //资源名称
            let resourceName = $("#upd_resourceName").val();

            //文件分类【课程资源：8，公共资源: 1】
            let type = $("#upd_type").val();

            //资源描述
            let resourceDesc = $("#upd_resourceDesc").val();

            //获取上传文件信息
            let file = $("#upd_file")[0].files[0];
            //获取资源扩展名
            let resourceSuffix = file.name.substr(file.name.lastIndexOf(".")).toLowerCase();

            console.log("resourceSuffix = " + resourceSuffix);

            //获取文件大小
            let resourceSize = file.size;

            console.log("resourceSize = " + resourceSize);

            //最后一次修改时间【在此做上传时间】
            let createTime = file.lastModifiedDate;

            console.log("createTime = " + createTime);

            let course = $("#upd_course").val();

            let chapter = $("#upd_chapter").val();

            let section = $("#upd_section").val();

            let resourceData = {};

            if (type = 1) {
                resourceData = {
                    id: id,
                    resourceName: resourceName,
                    resourceDesc: resourceDesc,
                    resourceSuffix: resourceSuffix,
                    resourceSize: resourceSize,
                    type: type,
                    createTime: createTime
                };
            } else if (type = 8) {
                resourceData = {
                    id:id,
                    resourceName: resourceName,
                    resourceDesc: resourceDesc,
                    resourceSuffix: resourceSuffix,
                    resourceSize: resourceSize,
                    type: type,
                    createTime: createTime,
                    course: course,
                    chapter: chapter,
                    section: section
                };
            }

            console.log(resourceData);

            /*let resourceJson = JSON.stringify(resourceData);*/

            $.ajax({
                method: "post",
                url: "/owep/resources/resourceList/updateResource",
                async: "true",
                data: resourceData,
                dataType: "text",
                /*contentType:"application/json",*/
                success: function (data) {
                    alert(data);
                    window.location.reload();
                },
                error: function (jqXRH) {
                    console.log(jqXRH);
                    alert("修改未成功")
                }
            });
            $('#update_form').submit();
        });


        //动态搜索选择下拉框
        testdataBsSuggest1;



        //添加事件
        $('#add_sure').click(function () {
            //alert("进入ajax")
             var form1 = document.forms["add_form"];
             var formData=new FormData(form1);
            $.ajax({
                method:"POST",
                url:"/owep/resources/resourceList/addResource",
                async: true,
                // data:$("#add_form").serialize(),
                data:formData,
                dataType:"text",
                contentType:false,//客户端发给服务端的，必须时false ，这样才能使用form表单采用multipart/form-data传输
                processData:false, //
                //contentType:"application/json",
                success:function(data){
                    //alert(data);

                    window.location.reload();
                },
                error: function (jqXRH) {
                    // alert($("#add_form").serialize());
                    console.log(jqXRH);
                    alert("添加未成功")
                }
            });


        });

        //更新时间
        $('#update_sure').click(function () {
            alert("更新成功");
        });

    });


    //搜索下拉选择框
    // var testdataBsSuggest1 = $("#resourceSuffix").bsSuggest({
    //     indexId: 2, //data.value 的第几个数据，作为input输入框的内容
    //     indexKey: 1, //data.value 的第几个数据，作为input输入框的内容
    //     //TODO 通过json显示数据
    //     data: {
    //         'value': [
    //             {
    //                 'id': "",
    //                 'word': 'pdf',
    //             },
    //             {
    //                 'id': "",
    //                 'word': 'docx',
    //             },
    //             {
    //                 'id': "",
    //                 'word': 'ppt',
    //             },
    //             {
    //                 'id': "",
    //                 'word': 'txt',
    //             }
    //         ]
    //     }
    // });



    var testdataBsSuggest1 = $("#add_type").bsSuggest({
        indexId: 2, //data.value 的第几个数据，作为input输入框的内容
        indexKey: 1, //data.value 的第几个数据，作为input输入框的内容
        //TODO 通过json显示数据
        data: {
            'value': [
                {
                    'id': 1,
                    'word': '公共资源',
                },
                {
                    'id': 8,
                    'word': '课程资源',
                },
            ]
        }
    });






    //添加资源 下拉选择
    var testdataBsSuggest1 = $("#add_course").bsSuggest({
        url: "/owep/resources/resourceList/findAllCourse",
        jsonp: null,
        showBtn: true,
        idField: "id",
        keyField: "courseName",
        effectiveFields: ["courseName"]
    }).on('onSetSelectValue', function (e, keyword) {
        $("#courseId").val(keyword.id);
        //销毁控件
        $("#add_chapter").bsSuggest("destroy");
        $("#add_chapter").bsSuggest({
            url: "/owep/resources/resourceList/findAllChapterByCourseId?id=" + keyword.id,
            showBtn: false,
            idField: "id",
            keyField: "chapterName",
            effectiveFields: ["chapterName"]
        }).on('onSetSelectValue', function (e, keyword) {
            $("#chapterId").val(keyword.id);
            //销毁控件
            $("#add_section").bsSuggest("destroy");
            $("#add_section").bsSuggest({
                url: "/owep/resources/resourceList/findAllSectionByChapterId?id=" + keyword.id,
                showBtn: false,
                idField: "id",
                keyField: "sectionName",
                effectiveFields: ["sectionName"]
            }).on('onSetSelectValue', function (e, keyword) {
                $("#sectionId").val(keyword.id);
            }).on('onUnSetSelectValue', function (e, keyword) {
                console.log("onUnSetSelectValue");
            });

        });
    });


    var testdataBsSuggest1 = $("#upd_type").bsSuggest({
        indexId: 2, //data.value 的第几个数据，作为input输入框的内容
        indexKey: 1, //data.value 的第几个数据，作为input输入框的内容
        //TODO 通过json显示数据
        data: {
            'value': [
                {
                    'id': 1,
                    'word': '公共资源',
                },
                {
                    'id': 8,
                    'word': '课程资源',
                },
            ]
        }
    });

    //修改资源 下拉选择
    var testdataBsSuggest1 = $("#upd_course").bsSuggest({
        url: "/owep/resources/resourceList/findAllCourse",
        jsonp: null,
        showBtn: true,
        idField: "id",
        keyField: "courseName",
        effectiveFields: ["courseName"]
    }).on('onSetSelectValue', function (e, keyword) {
        $("#updCourseId").val(keyword.id);
        //销毁控件
        $("#upd_chapter").bsSuggest("destroy");
        $("#upd_chapter").bsSuggest({
            url: "/owep/resources/resourceList/findAllChapterByCourseId?id=" + keyword.id,
            showBtn: false,
            idField: "id",
            keyField: "chapterName",
            effectiveFields: ["chapterName"]
        }).on('onSetSelectValue', function (e, keyword) {
            $("#updChapterId").val(keyword.id);
            //销毁控件
            $("#upd_section").bsSuggest("destroy");
            $("#upd_section").bsSuggest({
                url: "/owep/resources/resourceList/findAllSectionByChapterId?id=" + keyword.id,
                showBtn: false,
                idField: "id",
                keyField: "sectionName",
                effectiveFields: ["sectionName"]
            }).on('onSetSelectValue', function (e, keyword) {
                $("#updSectionId").val(keyword.id);
            }).on('onUnSetSelectValue', function (e, keyword) {
                console.log("onUnSetSelectValue");
            });

        });
    });






    //搜索下拉选择
    var testdataBsSuggest1 = $("#resourceSuffix").bsSuggest({
        url: "/owep/resources/resourceList/selectResourceSuffix",
        showBtn: true,
        idField: "",
        keyField: "resourceSuffix",
        effectiveFields: ["resourceSuffix"]
    }).on('onSetSelectValue', function (e, keyword) {
        $("#resource_suffix").val(keyword.resourceSuffix)

    }).on('onUnSetSelectValue', function (e, keyword) {
        console.log("onUnSetSelectValue");
    });







    var initdata = function () {
        var init = new Object();
        init.Init = function () {
            //加载之前先格式化 放在查询的时候起冲突
            $("#tb_major").bootstrapTable('destroy');
            $("#tb_major").bootstrapTable({
                url: '/owep/resources/resourceList/getResourceList',
                method: 'post',
                striped: true,  //是否显示行间隔色
                cache: false, //是否使用缓存
                pagination: true, //是否分页
                pageSize: 10,  //每页记录行数
                uniqueId: 'id',  //唯一id
                pageList: [10, 20],
                height: 550,
                queryParams: init.queryParams, // 传递参数
                queryParamsType: "limit",
                limit: 1,
                offset: 10,
                columns: [{
                    field: "checkbox",
                    checkbox: true,
                }, {
                    field: 'id',
                    title: "id",
                    align: "center",
                    visible: false //隐藏 让该字段不可见 为了后面更新和删除做准备
                }, {
                    field: 'resourceName',
                    title: "资源名称",
                    align: "center",
                }, {
                    field: 'resourceDesc',
                    title: "资源描述",
                    align: "center",
                }, {
                    field: 'type',
                    title: "类型",
                    align: "center",
                }, {
                    field: 'resourceSize',
                    title: "大小(kb)",
                    align: "center",
                }, {
                    field: 'resourceType',
                    title: "分类",
                    align: "center",
                }, {
                    field: 'createTime',
                    title: "上传时间",
                    align: "center",
                }, {
                    field: 'operator',
                    title: "操作",
                    align: "center",
                    valign: "middle",
                    formatter: actionFormatter, //方法调用
                    events: {
                        'click button[title=修改]': function (e, value, row, index) {//动态嵌入按键：编辑
                            //回显数据
                            echoDataForm('form[id="update_form"]', new Array("id", "resourceName",  "resourceDesc", "course", "chapter", "section", "type"), row);
                            //$('#update_resource').modal();
                        },
                        'click button[title=删除]': function (e, value, row, index) {//动态嵌入按键：删除
                            deleteRecord(e, value, row, index, "/owep/resources/resourceList/deleteResource", '#tb_major');
                        },
                    }
                }]

            });
        };

        init.queryParams = function (params) {
            console.log("params = " + params);
            console.log("$(\"#clientBelong\").val() = " + $("#resourceName").val());
            let temp = {  //这里的键的名字和控制器的变量名必须一直，这边改动，控制器也需要改成一样的
                offset: params.offset, //每次查询时的起始页码
                limit: params.limit, //页面大小，每页有多少条数据
                resourceName: $("#resourceName").val(), //要搜索的文本名称
                resourceSuffix: $("#resourceSuffix").val(),  //要搜索的文本类型
                time: $("#datepicker").val()  //要查询的时间
            };
            console.log(temp);
            return temp;
        };

        //搜索栏搜索功能


        //操作栏的格式化
        function actionFormatter(value, row, index) {
            var id = value;
            var result = "";
            result += "<button id='+id+' class='btn btn-white btn-sm' title='修改' style='margin-right: 10px' data-toggle=\"modal\" data-target=\"#update_resource\"><span class='glyphicon glyphicon-edit'></span></button>";
            result += "<button class='btn btn-white btn-sm'  style='margin-right: 10px' title='删除'><span class='glyphicon glyphicon-trash text-danger'></span></button>";
            return result;
        };

        return init;
    }
    /*面包屑 时间范围*/
    $('#date_case_1 .input-daterange').datepicker({
        keyboardNavigation: false,
        forceParse: false,
        autoClose: true,
        format: "yyyy-mm-dd",
        language: 'zh-CN',// 汉化
    });
    /*面试时间*/
    $('#interviewTime .date').datepicker({
        keyboardNavigation: false,
        forceParse: false,
        calendarWeeks: true,
        format: "yyyy-mm-dd",
        language: 'zh-CN',// 汉化
        autoclose: true
    });

</script>
<script>
    /* 资源类型input 控件添加失去焦点事件*/
    $(".form-control.org1").blur(function () {
        console.log("资源类型 js");
        if ($(this).val() == "课程资源") {
            $(".c_hidden").removeClass("hidden", "hidden");
        } else {
            $(".c_hidden").addClass("hidden", "hidden");
        }
    })
</script>
</body>
</html>